1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gtk.Popover; 26 27 private import glib.ConstructionException; 28 private import gobject.ObjectG; 29 private import gobject.Signals; 30 private import gtk.NativeIF; 31 private import gtk.NativeT; 32 private import gtk.ShortcutManagerIF; 33 private import gtk.ShortcutManagerT; 34 private import gtk.Widget; 35 private import gtk.c.functions; 36 public import gtk.c.types; 37 private import std.algorithm; 38 39 40 /** 41 * `GtkPopover` is a bubble-like context popup. 42 * 43 *  44 * 45 * It is primarily meant to provide context-dependent information 46 * or options. Popovers are attached to a parent widget. By default, 47 * they point to the whole widget area, although this behavior can be 48 * changed with [method@Gtk.Popover.set_pointing_to]. 49 * 50 * The position of a popover relative to the widget it is attached to 51 * can also be changed with [method@Gtk.Popover.set_position] 52 * 53 * By default, `GtkPopover` performs a grab, in order to ensure input 54 * events get redirected to it while it is shown, and also so the popover 55 * is dismissed in the expected situations (clicks outside the popover, 56 * or the Escape key being pressed). If no such modal behavior is desired 57 * on a popover, [method@Gtk.Popover.set_autohide] may be called on it to 58 * tweak its behavior. 59 * 60 * ## GtkPopover as menu replacement 61 * 62 * `GtkPopover` is often used to replace menus. The best was to do this 63 * is to use the [class@Gtk.PopoverMenu] subclass which supports being 64 * populated from a `GMenuModel` with [ctor@Gtk.PopoverMenu.new_from_model]. 65 * 66 * ```xml 67 * <section> 68 * <attribute name="display-hint">horizontal-buttons</attribute> 69 * <item> 70 * <attribute name="label">Cut</attribute> 71 * <attribute name="action">app.cut</attribute> 72 * <attribute name="verb-icon">edit-cut-symbolic</attribute> 73 * </item> 74 * <item> 75 * <attribute name="label">Copy</attribute> 76 * <attribute name="action">app.copy</attribute> 77 * <attribute name="verb-icon">edit-copy-symbolic</attribute> 78 * </item> 79 * <item> 80 * <attribute name="label">Paste</attribute> 81 * <attribute name="action">app.paste</attribute> 82 * <attribute name="verb-icon">edit-paste-symbolic</attribute> 83 * </item> 84 * </section> 85 * ``` 86 * 87 * # CSS nodes 88 * 89 * ``` 90 * popover[.menu] 91 * ├── arrow 92 * ╰── contents.background 93 * ╰── <child> 94 * ``` 95 * 96 * The contents child node always gets the .background style class 97 * and the popover itself gets the .menu style class if the popover 98 * is menu-like (i.e. `GtkPopoverMenu`). 99 * 100 * Particular uses of `GtkPopover`, such as touch selection popups or 101 * magnifiers in `GtkEntry` or `GtkTextView` get style classes like 102 * .touch-selection or .magnifier to differentiate from plain popovers. 103 * 104 * When styling a popover directly, the popover node should usually 105 * not have any background. The visible part of the popover can have 106 * a shadow. To specify it in CSS, set the box-shadow of the contents node. 107 * 108 * Note that, in order to accomplish appropriate arrow visuals, `GtkPopover` 109 * uses custom drawing for the arrow node. This makes it possible for the 110 * arrow to change its shape dynamically, but it also limits the possibilities 111 * of styling it using CSS. In particular, the arrow gets drawn over the 112 * content node's border and shadow, so they look like one shape, which 113 * means that the border width of the content node and the arrow node should 114 * be the same. The arrow also does not support any border shape other than 115 * solid, no border-radius, only one border width (border-bottom-width is 116 * used) and no box-shadow. 117 */ 118 public class Popover : Widget, NativeIF, ShortcutManagerIF 119 { 120 /** the main Gtk struct */ 121 protected GtkPopover* gtkPopover; 122 123 /** Get the main Gtk struct */ 124 public GtkPopover* getPopoverStruct(bool transferOwnership = false) 125 { 126 if (transferOwnership) 127 ownedRef = false; 128 return gtkPopover; 129 } 130 131 /** the main Gtk struct as a void* */ 132 protected override void* getStruct() 133 { 134 return cast(void*)gtkPopover; 135 } 136 137 /** 138 * Sets our main struct and passes it to the parent class. 139 */ 140 public this (GtkPopover* gtkPopover, bool ownedRef = false) 141 { 142 this.gtkPopover = gtkPopover; 143 super(cast(GtkWidget*)gtkPopover, ownedRef); 144 } 145 146 // add the Native capabilities 147 mixin NativeT!(GtkPopover); 148 149 // add the ShortcutManager capabilities 150 mixin ShortcutManagerT!(GtkPopover); 151 152 153 /** */ 154 public static GType getType() 155 { 156 return gtk_popover_get_type(); 157 } 158 159 /** 160 * Creates a new `GtkPopover`. 161 * 162 * Returns: the new `GtkPopover` 163 * 164 * Throws: ConstructionException GTK+ fails to create the object. 165 */ 166 public this() 167 { 168 auto __p = gtk_popover_new(); 169 170 if(__p is null) 171 { 172 throw new ConstructionException("null returned by new"); 173 } 174 175 this(cast(GtkPopover*) __p); 176 } 177 178 /** 179 * Returns whether the popover is modal. 180 * 181 * See [method@Gtk.Popover.set_autohide] for the 182 * implications of this. 183 * 184 * Returns: %TRUE if @popover is modal 185 */ 186 public bool getAutohide() 187 { 188 return gtk_popover_get_autohide(gtkPopover) != 0; 189 } 190 191 /** 192 * Returns whether the popover will close after a modal child is closed. 193 * 194 * Returns: %TRUE if @popover will close after a modal child. 195 */ 196 public bool getCascadePopdown() 197 { 198 return gtk_popover_get_cascade_popdown(gtkPopover) != 0; 199 } 200 201 /** 202 * Gets the child widget of @popover. 203 * 204 * Returns: the child widget of @popover 205 */ 206 public Widget getChild() 207 { 208 auto __p = gtk_popover_get_child(gtkPopover); 209 210 if(__p is null) 211 { 212 return null; 213 } 214 215 return ObjectG.getDObject!(Widget)(cast(GtkWidget*) __p); 216 } 217 218 /** 219 * Gets whether this popover is showing an arrow 220 * pointing at the widget that it is relative to. 221 * 222 * Returns: whether the popover has an arrow 223 */ 224 public bool getHasArrow() 225 { 226 return gtk_popover_get_has_arrow(gtkPopover) != 0; 227 } 228 229 /** 230 * Gets whether mnemonics are visible. 231 * 232 * Returns: %TRUE if mnemonics are supposed to be visible 233 * in this popover 234 */ 235 public bool getMnemonicsVisible() 236 { 237 return gtk_popover_get_mnemonics_visible(gtkPopover) != 0; 238 } 239 240 /** 241 * Gets the offset previous set with gtk_popover_set_offset(). 242 * 243 * Params: 244 * xOffset = a location for the x_offset 245 * yOffset = a location for the y_offset 246 */ 247 public void getOffset(out int xOffset, out int yOffset) 248 { 249 gtk_popover_get_offset(gtkPopover, &xOffset, &yOffset); 250 } 251 252 /** 253 * Gets the rectangle that the popover points to. 254 * 255 * If a rectangle to point to has been set, this function will 256 * return %TRUE and fill in @rect with such rectangle, otherwise 257 * it will return %FALSE and fill in @rect with the parent 258 * widget coordinates. 259 * 260 * Params: 261 * rect = location to store the rectangle 262 * 263 * Returns: %TRUE if a rectangle to point to was set. 264 */ 265 public bool getPointingTo(out GdkRectangle rect) 266 { 267 return gtk_popover_get_pointing_to(gtkPopover, &rect) != 0; 268 } 269 270 /** 271 * Returns the preferred position of @popover. 272 * 273 * Returns: The preferred position. 274 */ 275 public GtkPositionType getPosition() 276 { 277 return gtk_popover_get_position(gtkPopover); 278 } 279 280 /** 281 * Pops @popover down. 282 * 283 * This may have the side-effect of closing a parent popover 284 * as well. See [property@Gtk.Popover:cascade-popdown]. 285 */ 286 public void popdown() 287 { 288 gtk_popover_popdown(gtkPopover); 289 } 290 291 /** 292 * Pops @popover up. 293 */ 294 public void popup() 295 { 296 gtk_popover_popup(gtkPopover); 297 } 298 299 /** 300 * Presents the popover to the user. 301 */ 302 public void present() 303 { 304 gtk_popover_present(gtkPopover); 305 } 306 307 /** 308 * Sets whether @popover is modal. 309 * 310 * A modal popover will grab the keyboard focus on it when being 311 * displayed. Focus will wrap around within the popover. Clicking 312 * outside the popover area or pressing Esc will dismiss the popover. 313 * 314 * Called this function on an already showing popup with a new 315 * autohide value different from the current one, will cause the 316 * popup to be hidden. 317 * 318 * Params: 319 * autohide = %TRUE to dismiss the popover on outside clicks 320 */ 321 public void setAutohide(bool autohide) 322 { 323 gtk_popover_set_autohide(gtkPopover, autohide); 324 } 325 326 /** 327 * If @cascade_popdown is %TRUE, the popover will be 328 * closed when a child modal popover is closed. 329 * 330 * If %FALSE, @popover will stay visible. 331 * 332 * Params: 333 * cascadePopdown = %TRUE if the popover should follow a child closing 334 */ 335 public void setCascadePopdown(bool cascadePopdown) 336 { 337 gtk_popover_set_cascade_popdown(gtkPopover, cascadePopdown); 338 } 339 340 /** 341 * Sets the child widget of @popover. 342 * 343 * Params: 344 * child = the child widget 345 */ 346 public void setChild(Widget child) 347 { 348 gtk_popover_set_child(gtkPopover, (child is null) ? null : child.getWidgetStruct()); 349 } 350 351 /** 352 * Sets the default widget of a `GtkPopover`. 353 * 354 * The default widget is the widget that’s activated when the user 355 * presses Enter in a dialog (for example). This function sets or 356 * unsets the default widget for a `GtkPopover`. 357 * 358 * Params: 359 * widget = a child widget of @popover to set as 360 * the default, or %NULL to unset the default widget for the popover 361 */ 362 public void setDefaultWidget(Widget widget) 363 { 364 gtk_popover_set_default_widget(gtkPopover, (widget is null) ? null : widget.getWidgetStruct()); 365 } 366 367 /** 368 * Sets whether this popover should draw an arrow 369 * pointing at the widget it is relative to. 370 * 371 * Params: 372 * hasArrow = %TRUE to draw an arrow 373 */ 374 public void setHasArrow(bool hasArrow) 375 { 376 gtk_popover_set_has_arrow(gtkPopover, hasArrow); 377 } 378 379 /** 380 * Sets whether mnemonics should be visible. 381 * 382 * Params: 383 * mnemonicsVisible = the new value 384 */ 385 public void setMnemonicsVisible(bool mnemonicsVisible) 386 { 387 gtk_popover_set_mnemonics_visible(gtkPopover, mnemonicsVisible); 388 } 389 390 /** 391 * Sets the offset to use when calculating the position 392 * of the popover. 393 * 394 * These values are used when preparing the [struct@Gdk.PopupLayout] 395 * for positioning the popover. 396 * 397 * Params: 398 * xOffset = the x offset to adjust the position by 399 * yOffset = the y offset to adjust the position by 400 */ 401 public void setOffset(int xOffset, int yOffset) 402 { 403 gtk_popover_set_offset(gtkPopover, xOffset, yOffset); 404 } 405 406 /** 407 * Sets the rectangle that @popover points to. 408 * 409 * This is in the coordinate space of the @popover parent. 410 * 411 * Params: 412 * rect = rectangle to point to 413 */ 414 public void setPointingTo(GdkRectangle* rect) 415 { 416 gtk_popover_set_pointing_to(gtkPopover, rect); 417 } 418 419 /** 420 * Sets the preferred position for @popover to appear. 421 * 422 * If the @popover is currently visible, it will be immediately 423 * updated. 424 * 425 * This preference will be respected where possible, although 426 * on lack of space (eg. if close to the window edges), the 427 * `GtkPopover` may choose to appear on the opposite side. 428 * 429 * Params: 430 * position = preferred popover position 431 */ 432 public void setPosition(GtkPositionType position) 433 { 434 gtk_popover_set_position(gtkPopover, position); 435 } 436 437 /** 438 * Emitted whend the user activates the default widget. 439 * 440 * This is a [keybinding signal](class.SignalAction.html). 441 */ 442 gulong addOnActivateDefault(void delegate(Popover) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 443 { 444 return Signals.connect(this, "activate-default", dlg, connectFlags ^ ConnectFlags.SWAPPED); 445 } 446 447 /** 448 * Emitted when the popover is closed. 449 */ 450 gulong addOnClosed(void delegate(Popover) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 451 { 452 return Signals.connect(this, "closed", dlg, connectFlags ^ ConnectFlags.SWAPPED); 453 } 454 }